package main;

import com.opensymphony.xwork2.ActionSupport;
import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;

import java.util.*;
import java.io.Reader;
import java.io.IOException;
import java.net.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.text.ParseException;

import main.FreeBoardVO;
import main.EventBoardVO;
import main.JuBoardVO;
import main.LadyBoardVO;
import main.ManBoardVO;
import main.ReviewBoardVO;
import util.CalendarView;

public class NewListAction extends ActionSupport{

	public static Reader reader;
	public static SqlMapClient sqlMapper;
	
	private List<FreeBoardVO> freelist = new ArrayList<FreeBoardVO>();
	private List<EventBoardVO> eventlist = new ArrayList<EventBoardVO>();
	private List<JuBoardVO> jlist = new ArrayList<JuBoardVO>();
	private List<LadyBoardVO> ladylist = new ArrayList<LadyBoardVO>();
	private List<ManBoardVO> manlist = new ArrayList<ManBoardVO>();
	
	private List<ReviewBoardVO> reviewlist = new ArrayList<ReviewBoardVO>();

	private List<EventBoardVO> eventlistAll = new ArrayList<EventBoardVO>();
	Calendar now_cal = Calendar.getInstance();
	private CalendarView cal;
	private String nav;
	private String today;
	private int endDay;
	private int week;
	private int nowYear;
	private int nowMonth;
	private int nowDay;
	private int year;
	private int month;
	private int paramYear;
	private int paramMonth;

	public NewListAction() throws IOException
	{
		reader = Resources.getResourceAsReader("sqlMapConfig.xml");
		sqlMapper = SqlMapClientBuilder.buildSqlMapClient(reader);
		reader.close();		
	}
	
	public String execute() throws Exception {
		
		freelist = sqlMapper.queryForList("newfreeList");
		eventlist = sqlMapper.queryForList("neweventList");
		jlist = sqlMapper.queryForList("newjuList");
		ladylist = sqlMapper.queryForList("newladyList");
		manlist = sqlMapper.queryForList("newmanList");
		reviewlist = sqlMapper.queryForList("new-r-board-selectAll");
		eventlistAll = sqlMapper.queryForList("newEselectAll");
	
		/*int lastCount = reviewlist.size();
		int startCount = (lastCount-3) < 0? 0:lastCount-3;
		reviewlist = reviewlist.subList(startCount, lastCount);
		*/
		cal = new CalendarView();
		if(paramMonth != nowYear){
			cal = new CalendarView(paramYear, paramMonth);
		}
		nav = cal.getNav().toString();
		today = cal.getToday().toString();
		week = cal.getWeek();
		endDay = cal.getEndDay();
		nowYear=now_cal.get(Calendar.YEAR);
		nowMonth=now_cal.get(Calendar.MONTH)+1;
		nowDay=now_cal.get(Calendar.DAY_OF_MONTH);
		year = cal.getYear();
		month = cal.getMonth();
		
		return SUCCESS;
	}

	public List<FreeBoardVO> getFreelist() {
		return freelist;
	}

	public void setFreelist(List<FreeBoardVO> freelist) {
		this.freelist = freelist;
	}

	public List<EventBoardVO> getEventlist() {
		return eventlist;
	}

	public void setEventlist(List<EventBoardVO> eventlist) {
		this.eventlist = eventlist;
	}

	public List<JuBoardVO> getJlist() {
		return jlist;
	}

	public void setJlist(List<JuBoardVO> jlist) {
		this.jlist = jlist;
	}

	public List<LadyBoardVO> getLadylist() {
		return ladylist;
	}

	public void setLadylist(List<LadyBoardVO> ladylist) {
		this.ladylist = ladylist;
	}

	public List<ManBoardVO> getManlist() {
		return manlist;
	}

	public void setManlist(List<ManBoardVO> manlist) {
		this.manlist = manlist;
	}

	public List<ReviewBoardVO> getReviewlist() {
		return reviewlist;
	}

	public void setReviewlist(List<ReviewBoardVO> reviewlist) {
		this.reviewlist = reviewlist;
	}

	public List<EventBoardVO> getEventlistAll() {
		return eventlistAll;
	}

	public void setEventlistAll(List<EventBoardVO> eventlistAll) {
		this.eventlistAll = eventlistAll;
	}

	public String getNav() {
		return nav;
	}

	public void setNav(String nav) {
		this.nav = nav;
	}

	public String getToday() {
		return today;
	}

	public void setToday(String today) {
		this.today = today;
	}

	public int getEndDay() {
		return endDay;
	}

	public void setEndDay(int endDay) {
		this.endDay = endDay;
	}

	public int getWeek() {
		return week;
	}

	public void setWeek(int week) {
		this.week = week;
	}

	public int getNowYear() {
		return nowYear;
	}

	public void setNowYear(int nowYear) {
		this.nowYear = nowYear;
	}

	public int getNowMonth() {
		return nowMonth;
	}

	public void setNowMonth(int nowMonth) {
		this.nowMonth = nowMonth;
	}

	public int getNowDay() {
		return nowDay;
	}

	public void setNowDay(int nowDay) {
		this.nowDay = nowDay;
	}

	public int getYear() {
		return year;
	}

	public void setYear(int year) {
		this.year = year;
	}

	public int getMonth() {
		return month;
	}

	public void setMonth(int month) {
		this.month = month;
	}

	public int getParamYear() {
		return paramYear;
	}

	public void setParamYear(int paramYear) {
		this.paramYear = paramYear;
	}

	public int getParamMonth() {
		return paramMonth;
	}

	public void setParamMonth(int paramMonth) {
		this.paramMonth = paramMonth;
	}
	
	
}
